package campus.aiit.ssl.controller;

import campus.aiit.ssl.domain.model.Department;
import campus.aiit.ssl.service.DepartmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(description = "部门相关Api")
@RestController
public class DeptController {
    @Resource
    private DepartmentService departmentService;

    @ApiOperation("部门（删除）")
    @DeleteMapping("department")
    public int deleteBlock(Long id) {
        return departmentService.deleteByPrimaryKey(id);
    }

    @ApiOperation("部门（添加）")
    @PostMapping("department")
    public int insertBlock(@RequestParam String department) {
        return departmentService.insertByName(department);
    }

    @ApiOperation("部门（查询）")
    @GetMapping("department")
    public Department selectBlock(Long id) {
        return departmentService.selectByPrimaryKey(id);
    }

    @ApiOperation("部门（修改）")
    @PutMapping("department")
    public int updateBlock(@RequestBody Department department) {
        return departmentService.updateByPrimaryKeySelective(department);
    }

    @ApiOperation("部门（列表）")
    @GetMapping("departments")
    public Department[] getDepartments(){
        return departmentService.getDepartments();
    }
}
